<?php

class Utils_Mapper {

	public function objectsToArrays($objects) {
		$arrays = array();
		foreach ($objects as $object) {
			$array = $this->objectToArray($object);
			array_push($arrays, $array);
		}

		return $arrays;
	}

	public function objectToArray($object) {
		$array = array();
		$reflect = new ReflectionClass($object);
		$props = $reflect->getProperties();

		foreach ($props as $prop) {
			$method = 'get'.$prop;
			$value = $object->$method();
			$array[$prop] = $value;
		}

		return $array;
	}

	public function arraysToObjects($arrays, $className) {
		$objects = array();
		foreach ($arrays as $array) {
			$object = $this->arrayToObject($array, $className);
			array_push($objects, $object);
		}

		return $objects;
	}

	public function arrayToObject($array, $className) {
		$object = new $className();
		foreach ($array as $key => $value) {
			$method = 'set'.$key;
			$object->$method($value);
		}

		return $object;
	}
}